package com.jyserver.common.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
* @Description:
* @Time: 22:00 2019/3/21
* @Author: ChenYM
*
 * @param null
* @Return 
**/
public class Conntools {
    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    private Conntools(String driver, String url, String username, String password) {
        driver = driver;
        url = url;
        username = username;
        password = password;
    }

    private static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName(driver); //classLoader,加载对应驱动
            conn = (Connection) DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    private static boolean dosql(String sql) {
        try {
            Connection conn = getConn();
            PreparedStatement pstmt;
            pstmt = (PreparedStatement) conn.prepareStatement(sql);
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
